package ar.com.digitalbricks.view.imprenta.contacto.action;

import java.util.Collection;
import java.util.HashSet;

import ar.com.digitalbricks.view.imprenta.helper.TelefonoView;

import com.opensymphony.xwork2.Action;

public class CrearTelefono extends CrearContacto {
	private TelefonoView telefonoView;
	
	@SuppressWarnings("unchecked")
	public String execute() throws Exception {
		Collection<TelefonoView> telefonos = (Collection<TelefonoView>) session.get("telefonos");
		telefonos.add(this.getTelefonoView());
		session.put("telefonos", telefonos);
		this.setShowTelefono(false);
		return Action.SUCCESS;
	}
	
	public String preparar() throws Exception {
		if (!session.containsKey("telefonos")){
			session.put("telefonos", new HashSet<TelefonoView>());
		}
		this.setShowTelefono(true);
		this.setTelefonoView(new TelefonoView());
		return Action.INPUT;
	}
	
	public String cancelar() throws Exception {
		this.setShowTelefono(false);
		return Action.NONE;
	}

	public void setTelefonoView(TelefonoView telefonoView) {
		this.telefonoView = telefonoView;
	}

	public TelefonoView getTelefonoView() {
		return this.telefonoView;
	}
}